package daily.may0507;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class DateTimeFormatterTest {
    public static void main(String args[]) {
        //创建日期和时间对象
        LocalDateTime localDateTime = LocalDateTime.now();

        //通过静态常量方式获取格式化对象
        DateTimeFormatter isoFormatter = DateTimeFormatter.ISO_DATE_TIME;
        System.out.println("使用静态常量方式进行格式化：");
        String s = isoFormatter.format(localDateTime);
        System.out.println(s);

        //通过长格式(LONG)获取格式化对象
        DateTimeFormatter longFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
        System.out.println("使用长格式进行格式化：");
        String s1 = longFormatter.format(localDateTime);
        System.out.println(s1);

        //通过自定义方式获取格式化对象
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        System.out.println(dateFormatter.format(localDateTime));
    }
}
